package com.voxel.sense.infomsg.module.map.monitor.baseInfo;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.example.com.common.view.recycler.RecyclerAdapter;
import com.voxel.sense.infomsg.R;
import com.voxel.sense.infomsg.data.bean.ConditionBean;
import cyy.example.com.facotry.Factory;
import com.voxel.sense.infomsg.widget.adapter.AbsPickRecyclerAdapter;

import butterknife.BindView;

/**
 * Created by ChenYiYao on 2018/9/10.
 */
public class MapStaffMenuRecycAdapter extends AbsPickRecyclerAdapter {
    public MapStaffMenuRecycAdapter(AdapterListener<ConditionBean> listener) {
        super(listener);
    }

    @Override
    protected boolean handlerSatu(ConditionBean conditionBean) {
        return true;
    }

    @Override
    protected int getItemViewType(int position, ConditionBean conditionBean) {
        return R.layout.item_recycler_map_staff_menu;
    }

    @Override
    protected ViewHolder onCreateViewHolder(View root, int viewType) {
        return new ViewHolder(root);
    }

    static class ViewHolder extends RecyclerAdapter.ViewHolder<ConditionBean> {
        @BindView(R.id.iv_icon)
        ImageView iv_icon;
        @BindView(R.id.tv_name)
        TextView tv_name;

        public ViewHolder(View itemView) {
            super(itemView);
        }

        @Override
        protected void onBind(ConditionBean conditionBean) {
            tv_name.setText(conditionBean.getDesc());
            if (conditionBean.isSelect()) {
                String tipCode = conditionBean.getTipCode();
                tv_name.setTextColor(Factory.app().getResources().getColor(R.color.main_nav_select_color));
                if ("7".equals(tipCode)) {
                    loadIcon(R.mipmap.ic_zhifa);
                } else if ("6".equals(tipCode)) {
                    loadIcon(R.mipmap.ic_yunwei);
                } else if ("5".equals(tipCode)) {
                    loadIcon(R.mipmap.ic_xuancha);
                }
            } else {
                loadIcon(R.mipmap.ic_renyuan_normal);
                tv_name.setTextColor(Factory.app().getResources().getColor(R.color.textcolor_gray));
            }
        }

        private void loadIcon(int ResId) {
            Glide.with(iv_icon.getContext())
                    .load(ResId) // 加载路径
                    .apply(RequestOptions.centerInsideTransform())
                    .into(iv_icon);
        }
    }

}
